import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-ng-for',
  templateUrl: './ng-for.component.html',
  styleUrls: ['./ng-for.component.scss']
})
export class NgForComponent implements OnInit {
  items: any = [
    {
      value: "001",
      text: "数据1",
    },
    {
      value: "002",
      text: "数据2",
    }, 
    {
      value: "003",
      text: "数据3",
    },
    {
      value:"004",
      text:"数据4",
    }
  ]

  addOptions:any = {
    width:"140px",
    text:"新增一条数据到集合"
  };

  resetOptions:any = {
    width:"140px",
    text:"重置集合"
  };
  constructor() { }

  ngOnInit() {
  }

  addData(){
    let data = {
      value:"00"+(this.items.length+1).toString(),
      text:"数据"+(this.items.length+1).toString(),
    }
    this.items.push(data);
  }

  reset(){
    this.items = [
      {
        value: "001",
        text: "数据1",
      },
      {
        value: "002",
        text: "数据2",
      }, 
      {
        value: "003",
        text: "数据3",
      },
      {
        value:"004",
        text:"数据4",
      }
    ]
  }
}
